// featurePackage/pages/myScore/myScore.js
const app = getApp()
import {
  experienceChangeList
} from "../../../service/jb_scoreAndMoney_service"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    limit: 10,
    menuTop: app.globalData.menuButton.top,
    menuHeight: app.globalData.menuButton.height,
    navBarHeight: app.globalData.menuButton.top + app.globalData.menuButton.height,
    dataList: [],
    scoreDetail: {
      integral: 0,
      sumIntegral: 0,
      deductionIntegral: 0,
      frozenIntegral: 0,//冻结积分
    },
    isShowLoading: false,//加载状态出现
    isBottomShow: false,//是否没有更多数据了
    refreshFlag: false,
    myUserInfo: {
      promoterExperience: "0",
    },
    levelData: {
      isMax: false,
      nextNum: 0,
      nextName: '',
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.queryExperienceChangeList('refresh');
    console.log("JJLog:个人信息：" + JSON.stringify(app.globalData.userInfo));
    this.setData({
      myUserInfo: app.globalData.userInfo,
      levelData: app.globalData.levelData
    })
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  //积分变动列表
  queryExperienceChangeList(type) {
    wx.showLoading();
    experienceChangeList(this.data.page, this.data.limit).then(res => {
      wx.hideLoading();
      if (res.code == 200 && res.data) {
        let arr = (type == 'refresh' ? [] : this.data.dataList || []);
        arr = arr.concat(res.data.list || [])
        this.setData({
          dataList: arr,
          refreshFlag: false,
          isShowLoading: false,
          isBottomShow: res.data.totalPage == this.data.page ? true : false,
        })
      }
    }).catch(err => {
      console.error("JJLog:experienceChangeList", err);
      wx.hideLoading();
      wx.showToast({
        title: err || '加载失败',
        icon: "none"
      })
      if (this.data.page != 1) {
        this.setData({
          page: this.data.page - 1
        })
      }
      this.setData({
        refreshFlag: false,
      })
    })
  },
  pushToScore() {
    wx.navigateTo({
      url: '/featurePackage/pages/experienceExpain/experienceExpain',
    })
  },
  // 下拉刷新
  handleRefresh() {
    // TODO
    this.setData({
      page: 1,
      isBottomShow: false,
      refreshFlag: true,
    })
    this.queryExperienceChangeList('refresh');

  },

  // 加载更多
  handleLoadmore() {
    console.log('加载更多');
    if (this.data.isBottomShow) {
      return;
    }
    this.setData({
      isShowLoading: true,
      page: this.data.page + 1
    })
    this.queryExperienceChangeList()
  },



})